// pages/dictRoot2/dictRoot2.js
Page({
  data: {
    dictionary:[],
    search:false
  },
  onLoad: function (options) {
    let that=this;
    let search=wx.getStorageSync('searchObject');
    if(search.length>0){
      that.setData({
        search:true,
        dictionary:search
      })
    }else{
      let testid=options.testid
      wx.cloud.callFunction({
        name:'updata',
        data:{
          action:"select_dictionary",
          testid:testid
        },
        complete:res=>{
          console.log(res);
          that.setData({
            dictionary:res.result.data
          })
        }
      })
    }
  },
  toDict(e)
  {
    let that=this;
    var i=0;
    var dictionary=that.data.dictionary;
    for(i=0;i<dictionary.length;i++)
    {
      if (e.currentTarget.dataset.key == dictionary[i].name)
      {
        let dictionary = JSON.stringify(that.data.dictionary);
         wx.navigateTo
         ({ 
           url:"../dictionary/dictionary?index="+i+"&dictionary="+dictionary+"&search="+that.data.search, 
         }) 
       }
    }
  }
})